<?php
include 'config.php';
require_once 'db_indoherbal.php';

/*

masih ada bug di = 
*foto yang bisa diupload cuma JPG 
*pas waktu masukin email yang sudah ada, muncul pesan success, padahal belum masuk database
	-->email harus unique, jadi harus ada kode untuk ngecek apakah sudah ada? jika sudah maka muncul pesan error

nama
username
email
password
alamat
nohp
foto
*/

$nama			= $_REQUEST['nama'];
$username		= $_REQUEST['username'];
$email			= $_REQUEST['email'];
$alamat			= $_REQUEST['alamat'];
$password			= $_REQUEST['password'];
$nohp			= $_REQUEST['nohp'];
$foto			= null;

$set = true;

/*
   // begin Dave B's Q&D file upload security code
  $allowedExtensions = array("jpg","jpeg","gif","png");
  foreach ($_FILES as $file) {
    if ($file['tmp_name'] > '') {
      if (!in_array(end(explode(".", 
			strtolower($file['picture']))),
            $allowedExtensions)) {
       die($file['picture'].' is an invalid file type!<br/>'.
        '<a href="javascript:history.go(-1);">'.
        '&lt;&lt Go Back</a>');
      }
    }
  }
  // end Dave B's Q&D file upload security code 
*/

if ((($_FILES["picture"]["type"] = "jpeg")
|| ($_FILES["picture"]["type"] = "png")
|| ($_FILES["picture"]["type"] = "pjpeg"))
&& ($_FILES["picture"]["size"] < 200000)) {
	if($_FILES["picture"]["error"] > 0) {
		//echo '<div class="alert alert-danger">Error<button class="close" data-dismiss="alert">&times;</button></div>';
		$set = false;
		}
		
	else {
		if (file_exists("img/" . $_FILES["picture"]["name"])) {
			//echo '<div class="alert alert-warning">File sudah ada<button class="close" data-dismiss="alert">&times;</button></div>';
			//move_uploaded_file($_FILES["picture"]["img"], "picture2/" . $_FILES["picture"]["name"]);
			//$foto = "picture2/" . $_FILES["picture"]["name"];
			//echo "udah ada cuy";
		}
		else {
			move_uploaded_file($_FILES["picture"]["tmp_name"], "img/" . $_FILES["picture"]["name"]);
			$foto = "picture/" . $_FILES["picture"]["name"];
		}
	}
}

	$datauser = array(
		'nama' => $nama,
		'username' => $username,
		'email' => $email,
		'password' => $password,
		'alamat' => $alamat,
		'nohp' => $nohp,
		'foto' => $foto,
	);
	
	$db = new db_indoherbal($host,$user,$pass,$dbnm);
	$db->set_data($datauser);
	//header("location:login.php?success");
	exit();




?>
<?ob_flush();?>